package o;

import com.google.android.exoplayer2.extractor.Extractor;
import java.io.IOException;
import o.aea.e;

public final class aeg implements Extractor {
    public static final adw ˊ = aem.ˎ;
    private static final int ˏ = anr.ᐝ("FLV");
    private final anc ʻ = new anc();
    private int ʼ = 1;
    private ady ʽ;
    private boolean ˊॱ;
    private final anc ˋ = new anc(9);
    private long ˋॱ;
    private final anc ˎ = new anc(4);
    private int ˏॱ;
    private int ͺ;
    private final anc ॱ = new anc(11);
    private int ॱˊ;
    private long ॱॱ = -9223372036854775807L;
    private ael ॱᐝ;
    private final aen ᐝ = new aen();
    private aee ᐝॱ;

    public boolean ˎ(adv o_adv) throws IOException, InterruptedException {
        o_adv.ˎ(this.ˎ.ˏ, 0, 3);
        this.ˎ.ˋ(0);
        if (this.ˎ.ˏॱ() != ˏ) {
            return false;
        }
        o_adv.ˎ(this.ˎ.ˏ, 0, 2);
        this.ˎ.ˋ(0);
        if ((this.ˎ.ॱॱ() & 250) != 0) {
            return false;
        }
        o_adv.ˎ(this.ˎ.ˏ, 0, 4);
        this.ˎ.ˋ(0);
        int ॱᐝ = this.ˎ.ॱᐝ();
        o_adv.ˏ();
        o_adv.ˊ(ॱᐝ);
        o_adv.ˎ(this.ˎ.ˏ, 0, 4);
        this.ˎ.ˋ(0);
        if (this.ˎ.ॱᐝ() == 0) {
            return true;
        }
        return false;
    }

    public void ˏ(ady o_ady) {
        this.ʽ = o_ady;
    }

    public void ˊ(long j, long j2) {
        this.ʼ = 1;
        this.ॱॱ = -9223372036854775807L;
        this.ॱˊ = 0;
    }

    public void ॱ() {
    }

    public int ˎ(adv o_adv, adz o_adz) throws IOException, InterruptedException {
        while (true) {
            switch (this.ʼ) {
                case 1:
                    if (ॱ(o_adv)) {
                        break;
                    }
                    return -1;
                case 2:
                    ˋ(o_adv);
                    break;
                case 3:
                    if (ˊ(o_adv)) {
                        break;
                    }
                    return -1;
                case 4:
                    if (!ˏ(o_adv)) {
                        break;
                    }
                    return 0;
                default:
                    throw new IllegalStateException();
            }
        }
    }

    private boolean ॱ(adv o_adv) throws IOException, InterruptedException {
        boolean z = false;
        if (!o_adv.ˊ(this.ˋ.ˏ, 0, 9, true)) {
            return false;
        }
        this.ˋ.ˋ(0);
        this.ˋ.ˎ(4);
        int ʽ = this.ˋ.ʽ();
        boolean z2 = (ʽ & 4) != 0;
        if ((ʽ & 1) != 0) {
            z = true;
        }
        if (z2 && this.ᐝॱ == null) {
            this.ᐝॱ = new aee(this.ʽ.ˊ(8, 1));
        }
        if (z && this.ॱᐝ == null) {
            this.ॱᐝ = new ael(this.ʽ.ˊ(9, 2));
        }
        this.ʽ.ˊ();
        this.ॱˊ = (this.ˋ.ॱᐝ() - 9) + 4;
        this.ʼ = 2;
        return true;
    }

    private void ˋ(adv o_adv) throws IOException, InterruptedException {
        o_adv.ॱ(this.ॱˊ);
        this.ॱˊ = 0;
        this.ʼ = 3;
    }

    private boolean ˊ(adv o_adv) throws IOException, InterruptedException {
        if (!o_adv.ˊ(this.ॱ.ˏ, 0, 11, true)) {
            return false;
        }
        this.ॱ.ˋ(0);
        this.ͺ = this.ॱ.ʽ();
        this.ˏॱ = this.ॱ.ˏॱ();
        this.ˋॱ = (long) this.ॱ.ˏॱ();
        this.ˋॱ = (((long) (this.ॱ.ʽ() << 24)) | this.ˋॱ) * 1000;
        this.ॱ.ˎ(3);
        this.ʼ = 4;
        return true;
    }

    private boolean ˏ(adv o_adv) throws IOException, InterruptedException {
        boolean z = true;
        if (this.ͺ == 8 && this.ᐝॱ != null) {
            ˋ();
            this.ᐝॱ.ॱ(ᐝ(o_adv), this.ॱॱ + this.ˋॱ);
        } else if (this.ͺ == 9 && this.ॱᐝ != null) {
            ˋ();
            this.ॱᐝ.ॱ(ᐝ(o_adv), this.ॱॱ + this.ˋॱ);
        } else if (this.ͺ != 18 || this.ˊॱ) {
            o_adv.ॱ(this.ˏॱ);
            z = false;
        } else {
            this.ᐝ.ॱ(ᐝ(o_adv), this.ˋॱ);
            long ˎ = this.ᐝ.ˎ();
            if (ˎ != -9223372036854775807L) {
                this.ʽ.ˎ(new e(ˎ));
                this.ˊॱ = true;
            }
        }
        this.ॱˊ = 4;
        this.ʼ = 2;
        return z;
    }

    private anc ᐝ(adv o_adv) throws IOException, InterruptedException {
        if (this.ˏॱ > this.ʻ.ˎ()) {
            this.ʻ.ॱ(new byte[Math.max(this.ʻ.ˎ() * 2, this.ˏॱ)], 0);
        } else {
            this.ʻ.ˋ(0);
        }
        this.ʻ.ॱ(this.ˏॱ);
        o_adv.ˏ(this.ʻ.ˏ, 0, this.ˏॱ);
        return this.ʻ;
    }

    private void ˋ() {
        if (!this.ˊॱ) {
            this.ʽ.ˎ(new e(-9223372036854775807L));
            this.ˊॱ = true;
        }
        if (this.ॱॱ == -9223372036854775807L) {
            this.ॱॱ = this.ᐝ.ˎ() == -9223372036854775807L ? -this.ˋॱ : 0;
        }
    }
}
